<template>
    <div>
        <div style="margin-bottom: 20px;margin-top: 10px;width: 810px;">
            <label>标题：</label>
            <el-input
                style="width: 450px; margin-right: 20px"
                type="text"
                v-model="title"
            ></el-input>
            <label>时间：</label>
            <el-date-picker
                v-model="createDate"
                type="date"
                value-format="yyyy-MM-dd"
                :default-value="createDate"
            ></el-date-picker>
        </div>
        <div
            ref="editor"
            class="addDynamicEditor"
            style="width: 800px;"
        ></div>
        <div style="margin-top:20px;text-align:center; width: 800px;">

            <el-button
                type="primary"
                @click="submit"
            >提交</el-button>
            <el-button>重置</el-button>
        </div>
    </div>
</template>

<script>
import E from "wangeditor";
export default {
    name: "Editor",
    data() {
        return {
            editor: null,
            title: "",
            content: "",
            createDate: ""
        };
    },
    methods: {
        // 初始化富文本编辑器
        initEditor() {
            this.editor = new E(this.$refs.editor);
            // this.editor.customConfig.uploadImgShowBase64 = true;
            this.editor.customConfig.showLinkImg = false;
            this.editor.customConfig.onchange = html => {
                this.editorContent = html;
            };
            this.editor.customConfig.zIndex = 100;
            this.editor.create();
        },
        submit() {
            var data = {};
            data["title"] = this.title;
            this.content = this.editor.txt.html();
            data["content"] = this.content;
            data.createDate = this.createDate;
            this.$http({
                url: "/companyDynamic/add",
                method: "post",
                headers: {
                    "Content-Type":
                        "application/x-www-form-urlencoded; charset=UTF-8"
                },
                params: data
            })
                .then(response => {
                    this.$message({
                        message: response.data.message,
                        type: "success"
                    });
                })
                .catch(err => err);
        }
    },
    mounted() {
        this.createDate = this.getDate();
        this.initEditor();
    }
};
</script>

<style>
</style>